IF EXISTS(SELECT * FROM SYSOBJECTS WHERE name = 'Students' AND xtype = 'U')
BEGIN
	DROP TABLE Students
END
GO

IF NOT EXISTS(SELECT * FROM SYSOBJECTS WHERE name = 'Students' AND xtype = 'U')
BEGIN
	CREATE TABLE Students
	(
		MatriculaId		uniqueidentifier not null,
		Nome			varchar(100) not null,
		Cpf				char(11) not null,
		Nascimento		date,
		Sexo	        char(1) not null,
		bt_Removed	    bit not null,
		Formado			bit not null,
		Rg				varchar(10) not null,
		Endereco		varchar(100),
		Cep				char(8),
		Telefone		varchar(15),
		Email			varchar(100),
		DegreeCourseId	int not null,
		DtIngresso		date,
		Periodo			char(1) not null,
		UserId			int not null,

	)
END
GO

IF NOT EXISTS(SELECT * FROM SYSOBJECTS WHERE name = 'pk_StudentsId' AND xtype = 'PK')
BEGIN
	ALTER TABLE Students
	ADD CONSTRAINT pk_StudentsId PRIMARY KEY ([MatriculaId])
END
GO

IF NOT EXISTS(SELECT * FROM SYSOBJECTS WHERE name = 'fk_StudentsId' AND xtype = 'F')
BEGIN
	ALTER TABLE Students
	ADD CONSTRAINT fk_UserId FOREIGN KEY ([userId])
	REFERENCES Users
END
GO